using System.Collections.Generic;
using UnityEngine;

public class BackpackUI : MonoBehaviour
{
	public TweenAlpha backpackTweener;

	public UIGrid backpackGrid;

	public GameObject backPackGroup;

	public UILabel lbGuide;

	public BackPackItemPrefab[] listItems;

	public Game game;

	private bool show;

	private List<int> backPackWeapons;

	private void Start()
	{
		backPackWeapons = new List<int>();
		backpackTweener.ResetToBeginning();
	}

	public void InitBackPack(List<int> weapons)
	{
		backPackWeapons = weapons;
		SetBackPackButtons();
	}

	private void SetBackPackButtons()
	{
		bool active = false;
		BackPackItemPrefab[] array = listItems;
		foreach (BackPackItemPrefab backPackItemPrefab in array)
		{
			backPackItemPrefab.gameObject.SetActive(backPackWeapons.Contains(backPackItemPrefab.id));
			if (backPackItemPrefab.gameObject.activeSelf)
			{
				active = true;
			}
		}
		backpackGrid.Reposition();
		backPackGroup.SetActive(active);
	}

	public void ClickBackPack()
	{
		if (!show)
		{
			ShowBackPack();
		}
		else
		{
			HideBackPack();
		}
	}

	private void ShowBackPack()
	{
		show = true;
		backpackTweener.PlayForward();
		lbGuide.gameObject.SetActive(value: true);
	}

	private void HideBackPack()
	{
		show = false;
		backpackTweener.PlayReverse();
		lbGuide.gameObject.SetActive(value: false);
	}

	public void EquipWeapon(int id)
	{
		if (!game.playerController.info.freeze)
		{
			backPackWeapons.Remove(id);
			SetBackPackButtons();
			game.SpawnWeapon(id, game.playerController.info, Vector3.zero, forcePick: true);
			ClickBackPack();
		}
	}
}
